<template>
    <view :style="objColor">
        <!-- mine/pages/integralSubsidiary/integralSubsidiary.wxml -->
        <view>
            <view>
                <view class="subsidiary-tabs">
                    <view v-for="(item, index) in subsidiaryTabs" :key="index">
                        <view :class="'subsidiary-tabs-item ' + (index == currentIndex ? 'active' : 'subsidiary-tabs-item')" @tap="tabsIndex" :data-index="index">{{ item }}</view>
                    </view>   
                </view>
                <view class="subsidiary-header">
                    <view class="subsidiary-date">
                        <view class="type" @tap="checkTime">
                            {{ MYDCurrentDate }}
                            <image class="img" src="https://oos-cn.ctyunapi.cn/front-end/static/static/xiala.png"></image>
                        </view>
                    </view>
                    <view class="subsidiary-status">
                        <view class="operate-status">
                            <view class="operate">增加</view>
                            <view class="operate-value" v-if="positive!=0">+{{positive}}</view>
							<view class="operate-value" v-else>0</view>
                        </view>
                        <view class="operate-status2">
                            <view class="operate">扣减</view>
                            <view class="operate-value" v-if="negative!=0">-{{negative}}</view>
							<view class="operate-value" v-else>0</view>
                        </view>
                    </view>
                </view>
                <view v-if="integralList.length!=0">
                    <view class="integral-list">
                        <view class="integral-list-item" v-for="(item, index) in integralList" :key="index">
                            <view class="integral-list-item-content">
                                <view class="integral-list-item-children1">
                                <view class="type" v-if="item.sourceType == 2">成长等级会员</view>
                                <view class="type" v-if="item.sourceType == 3">付费会员</view>
                                <view class="type" v-if="item.sourceType == 4">推广</view>
                                <view class="type" v-if="item.sourceType == 5">充值奖励活动</view>
                                <view class="type" v-if="item.sourceType == 6">累计消费活动</view>
                                <view class="type" v-if="item.sourceType == 7">单笔折扣活动</view>
                                <view class="type" v-if="item.sourceType == 8">站点优惠活动</view>
                                <view class="type" v-if="item.sourceType == 9">邀请奖励</view>
                                <view class="type" v-if="item.sourceType == 10">新客有礼</view>
                                <view class="type" v-if="item.sourceType == 11">多人拼团</view>
                                <view class="type" v-if="item.sourceType == 12">消耗</view>
                                <view class="type" v-if="item.sourceType == 13">退款冻结</view>
                                <view class="type" v-if="item.sourceType == 14">退款核销</view>
                                <view class="type" v-if="item.sourceType == 16">充电消费</view>
                                   
                                   <view class="price" v-if="item.type == 1">+{{ item.amount}}
                                   </view>
                                   <view v-else-if="item.type == 2">-{{ item.amount}}
                                   </view>
                                   <view v-else>{{ item.amount }}</view>
                                </view>
                                <view class="integral-list-item-children2">
                        <!--            <view class="integral-num-name">
                                        积分:
                                        <text class="integral-num">{{ item.sumIntegral / 1000 }}</text>
                                    </view> -->
                                    <view class="integral-date">{{ item.createTime }}</view>
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
                <view v-if="integralList.length==0">
                		<Upgrading text1="您暂无积分明细记录~"></Upgrading>
                	</view>
                <view v-if="integralList.length==0" class="goBtn" @click="goRecharge">去充电</view>
            </view>
        </view>
      <!--  <u-popup  position="bottom" custom-style="width:702rpx;margin:24rpx;border-radius: 16rpx;" @close="onClose"  mode='top'>
        </u-popup> -->
		 <u-datetime-picker :show="showTime" mode="year-month" v-model="currentDate"  :closeOnClickOverlay='true' @close="onClose" @cancel='onClose' @confirm="onConfirm"  :itemHeight="100"/>
    </view>
</template>

<script>
import Upgrading from '../../../components/upgrading/upgrading';

// exports.__esModule = true; // mine/pages/integralSubsidiary/integralSubsidiary.ts
	import {
		integralDetail
	} from '../../../api/marketing/vip'
var util_1 = require('./../../../utils/util.js');
export default {
    components: {
        Upgrading
    },
    data() {
        return {
            subsidiaryTabs: ['全部', '增加', '扣减'],
            currentIndex: 0,
            showTime: false,
            currentDate: new Date().getTime(),
            MYDCurrentDate: '请选择时间',
            integralList: [],
            startTime: null,
            sTime: '2023-9',
            endTime: null,
            type: 0,
            page: 1,
            pageNum: 0,
            positive: 0,//收入
            negative: 0//支出
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
        this.IntegralDetail(this.type, 4);
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        var page = this.page + 1; //获取当前页数并+1

        if (this.page < this.pageNum) {
            this.page= page
            this.IntegralDetail(this.type, 4);
        }
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.page = 1;
        if (this.integralList.length) {
            uni.showNavigationBarLoading(); //在标题栏中显示加载图标

            this.IntegralDetail(this.type, 5);
        }
    },
    methods: {
		//去充电
		goRecharge(){
			uni.switchTab({
				url: '/pages/index/index'
			});
		},
        tabsIndex: function (e) {
            // console.log(e)
            var that = this;
            var index = e.currentTarget.dataset.index;

            switch (index) {
                case 0:
                    that.type=0,
                        that.page=1
                    this.IntegralDetail(this.type, 1);
                    break;

                case 1:
                    that.type=1,
                        that.page=1
                    this.IntegralDetail(this.type, 2);
                    break;

                case 2:
                    that.type= 2,
                        that.page= 1
                    this.IntegralDetail(this.type, 3);
                    break;
            }

            that.currentIndex= index
        },

        //选择时间
        checkTime: function () {
            // console.log(111)
            this.showTime= true
        },

        onInput: function (event) {
            //   console.log(event,2323)
            if (this.showTime) {
                this.sTime= util_1.formatYMTime(event.detail)
            }
        },

        onCancel: function () {
            this.showTime= false
        },

        onConfirm: function (e) {
            this.showTime=false
			this.sTime=util_1.formatYMTime(e.value)
			this.MYDCurrentDate= this.sTime || '请选择时间'
            this.IntegralDetail(this.type, 1);
        },

        IntegralDetail: function (type, index) {
            var that = this;

            switch (that.sTime) {
                case null:
                    that.startTime= '2023年9月'
                    break;

                default:
                    that.startTime= that.sTime + '-01 00:00:00',
                    that.endTime=that.sTime + '-31 23:59:59'
                    break;
            }

            integralDetail({
                    current: that.page,
                    size: 10,
                    type: type,
                    monthTime: that.startTime,
                    // endTime: that.endTime
                })
                .then(function (res) {
                    if (res.code ==200) {
                        // 总数据
                        var total = res.data.total;
                        var pageNum = Math.ceil(total / 10);
                        var integralList = void 0;

                        switch (index) {
                            // 全部
                            case 1:
                                integralList = res.data.marketAppUserIntegralInoutList;
                                break;
                            // 增加

                            case 2:
                                integralList = res.data.marketAppUserIntegralInoutList;
                                break;
                            // 减少

                            case 3:
                                integralList = res.data.marketAppUserIntegralInoutList;
                                break;
                            // 页面初始化及上拉加载

                            case 4:
                                integralList = that.integralList.concat(res.data.marketAppUserIntegralInoutList);
                                break;
                            // 下拉刷新

                            case 5:
                                integralList = res.data.marketAppUserIntegralInoutList;
                                uni.hideNavigationBarLoading(); //在标题栏中隐藏加载图标

                                uni.stopPullDownRefresh();
                                break;
                        }

                        that.integralList= integralList
						if(res.data.distributePoint){
						that.positive=res.data.distributePoint
						}
						if(res.data.absorptivePoint){
						that.negative=res.data.absorptivePoint
						}
						console.log('1111111',that.integralList)
                            that.pageNum= pageNum
                    }
                })
                ['catch'](function (err) {
                    console.log(err);
                });
        },
        onClose() {
			this.showTime=false
            console.log('占位：函数 onClose 未声明');
        }
    }
};
</script>
<style lang="less">
/* mine/pages/integralSubsidiary/integralSubsidiary.wxss */
@import "../../../commin/commin.less";
page{
    background-color:@text-color6;
}
.goBtn{
	width: 638rpx;
	height: 88rpx;
	background: var(--btnColor);
	border-radius: 44rpx;
	font-size: 30rpx;
	font-family: PingFang SC-Medium, PingFang SC;
	font-weight: 400;
	color: #FFFFFF;
	display:flex;
	justify-content: center;
	    align-items: center;
	    margin: 0 auto;
	    margin-bottom: 20rpx;
}
.subsidiary-tabs{
    display: flex;
    justify-content: space-around;
    align-items: center;
    .paddings(32rpx,0,32rpx,0);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: @text-color6;
    z-index: 999;
    .subsidiary-tabs-item,.active{
        .kuangao(182rpx,64rpx);
        background:@white-color;
        border-radius: 32rpx;
        .fontsize(30rpx);
        font-family: PingFang SC;
        font-weight: 500;
        color: @text-color3;
        .textalign();
        line-height:64rpx;
    }
    .active{
        background: rgba(109,177,46,0.102);
        .borders(1rpx,@blue);
        font-weight: bold;
        color:@blue;
    }
}
.subsidiary-header{
    display:flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    width: 100%;
    top: 131rpx;
    right: 0rpx;
    left: 0rpx;
    background-color: @text-color6;
    .subsidiary-date{
        .fontsize(34rpx);
        font-family: PingFang SC;
        font-weight: bold;
        color: #18181A;
        display: flex;
        align-items: center;
        margin-left: 57rpx;
        .type{
            display: flex;
            align-items: center;
            .img{
                .kuangao(25rpx,13rpx);
                margin-left: 24rpx;
            }
        }
    }
    .subsidiary-status{
        margin-right: 77rpx;
        display: flex;
        justify-content: start;
        align-items: center;
        .operate-status,.operate-status2{
            display: flex;
            justify-content: start;
            align-items: center;
            .operate{
                .fontsize(24rpx);
                font-family: PingFang SC;
                font-weight: 500;
                color: @text-color3;
            }
            .operate-value{
                .fontsize(30rpx);
                font-family: PingFang SC;
                font-weight: bold;
                color: @blue;
                margin-left: 18rpx;
            }
        }
        .operate-status2{
            margin-left: 46rpx;
        }

    }
}

.integral-list{
    width: 94%;
    margin-top: 213rpx;
    margin-left: 3%;
    background: linear-gradient(0deg, #FFFFFF, #F4F6F8);
    border: 2rpx solid #FFFFFF;
    box-shadow: 4rpx 7rpx 20rpx 0px rgba(166,171,179,0.24);
    border-radius: 16rpx;
    .integral-list-item{
        /*margin: 0 24rpx;*/
        /*background-color: #fff;*/
        // border-radius: 16rpx;
        /*padding-top:40rpx;*/
        .integral-list-item-content{
            margin: 0rpx 32rpx ;
            border-bottom: 1rpx dashed #C0C4CC;
            .integral-list-item-children2{
                margin-bottom:40rpx ;
            }
            .integral-list-item-children1,.integral-list-item-children2{
                width: 100%;
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-top: 25rpx;
                .type{
                    font-size: 30rpx;
                    font-family: PingFang SC;
                    font-weight: bold;
                    color: #303133;
                }
                .price{
                    font-size: 34rpx;
                    font-family: DIN;
                    font-weight: bold;
                    color: #FC724C;
                }
                .integral-num-name{
                    font-size: 26rpx;
                    font-family: PingFang SC;
                    font-weight: 500;
                    color: #606266;
                }
                .integral-num{
                    font-size: 26rpx;
                    font-family: PingFang SC;
                    font-weight: 500;
                    color: #FC724C;
                }
                .integral-date{
                    font-size: 24rpx;
                    font-family: PingFang SC;
                    font-weight: 400;
                    color: #606266;
                }

            }
        }

    }
    .integral-list-item:nth-child(1){
        border-top-left-radius: 16rpx;
        border-top-right-radius: 16rpx;
    }
    .integral-list-item:nth-last-child(1){
        border-bottom-left-radius: 16rpx;
        border-bottom-right-radius: 16rpx;
        .integral-list-item-content{
            border-bottom:none;
            .integral-list-item-children2{
                padding-bottom: 40rpx;
            }
        }

    }

}
.u-toolbar__wrapper__confirm{
    color: @blue !important;;
}
</style>
